import uuid
from Connector.client import res_success, res_err


class CmdMeshColorSet:
    name = "cmd_mesh_color_set"
    id = uuid.uuid4()

    def __init__(self, service, Params, Tag, Type):
        self.service = service
        self.params = Params
        self.tag = Tag
        self.type = Type

    async def execute(self):
        actor_id = self.params.get("ActorId", None)
        ids = self.params.get("ids", None)
        if ids is None:
            await res_err(self.tag, self.type, "参数错误")
            return
        color = self.params.get("color", None)
        colors = self.params.get("colors", None)
        if actor_id is None:
            ac = self.service.get_first_actor()
            if ac is None:
                ac.set_cells_color(ids, color, colors)
                self.service.app.render()
        await res_success(self.tag, self.type, {})
